package com.example.venue_reservation_service.config;

import com.example.venue_reservation_service.service.ReservationService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.Calendar;

@Configuration
@Slf4j
public class SchedulerConfig {

//    @Resource
//    private ReservationService reservationService;
//
//    //定义定时任务
//    @Scheduled(cron = "0 0 9-13 * * ?") // 每天9:00到13:00每小时执行一次
//    public void scheduledTask() {
//
//        // 处理过期的预约订单
//        Calendar calendar = Calendar.getInstance();
//        int hour = calendar.get(Calendar.HOUR_OF_DAY);
//        reservationService.dealReservation( hour - 8);
//
//        System.out.println("定时任务执行于: " + new java.util.Date());
//    }

    // 配置 ThreadPoolTaskScheduler
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(1); // 设置线程池大小
        scheduler.setThreadNamePrefix("one-time-task-");
        return scheduler;
    }

}

